package org.smile.homework01.kevin.Parking_handle;



import lombok.Data;

import java.util.Scanner;
@Data
public class Vehicle implements Generator {
    Scanner in = new Scanner(System.in);



    //1 成员变量  生成车
    private String number;
    private String type;
    public Vehicle(){
        this.type = generateType();
        this.number = generateNumber();
        System.out.println("请输入入场时间：");
        inTime = in.nextInt();
    }
    //1.1 车牌号
    //1.2 车的类型（大中小）
    //1.3 占用的车位
    private ParkingSpace parkingSpace;

    //1.3 入场时间
    private Integer inTime;

    //1.4 出场时间
private Integer exitTime;
    //2 进入停车场
    public void enterParkingLot(ParkingLot parkingLot) {

//        parkingLot.handleEnterParkingLot(this, inTime);
        System.out.println(this.number + "进入停车场");

        Integer parkingSpaceNumber = lookForParkingSpace(parkingLot);
        if (parkingSpaceNumber != null) {
            enterParkingSpace(parkingLot, parkingSpaceNumber);
        } else {
            leaveParkingLot(parkingLot);
        }

    }

    //3.找停车位
    public Integer lookForParkingSpace(ParkingLot parkingLot) {

        for (ParkingSpace parkingSpace : parkingLot.getParkingSpaces()) {
            if (!parkingSpace.isOccupied() && parkingSpace.getType().equals(this.getType())) {
                System.out.println(this.getNumber() + "找停车位");
                return parkingSpace.getNumber();
            }
        }
        System.out.println(this.getNumber() + "没找到停车位");
        return null;


    }

    //4.进入停车位
    public void enterParkingSpace(ParkingLot parkingLot, Integer parkingSpaceNumber) {
        parkingLot.handleEnterParkingSpace(this, parkingSpaceNumber);
        System.out.println(this.number + "进入停车位");
    }

    //5.离开停车位
    public void leaveParkingSpace(ParkingLot parkingLot, Integer parkingSpaceNumber) {
        parkingLot.handleLeaveParkingSpace(parkingSpaceNumber);
        System.out.println(this.number + "离开停车位");
    }

    //6.离开停车场
    public void leaveParkingLot(ParkingLot parkingLot){
        System.out.println("请输入车辆离场时间");
        Integer exitTime = in.nextInt();
        parkingLot.handleLeaveParkingLot(this, exitTime);
        System.out.println(this.number + "离开停车场");
    }

    public void describe() {
        System.out.format("车牌号：%s, [车位类型：%s]\n", this.getNumber(), this.getType());
    }

}
